package com.dm.cloud.auth.service.impl;

import cn.hutool.core.util.StrUtil;
import com.dm.cloud.auth.common.dto.AuthRoleDTO;
import com.dm.cloud.tkmybatis.service.BaseMapper;
import com.dm.cloud.auth.mapper.AuthRoleMapper;
import com.dm.cloud.auth.service.AuthRoleService;
import com.dm.cloud.auth.common.po.AuthRole;
import com.dm.cloud.core.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
   * @author hcx
   * @type AuthRoleServiceImpl.java
   * @desc AuthRole serviceImpl
   */
@Service

@Transactional

public class AuthRoleServiceImpl implements AuthRoleService {


    @Autowired
    private AuthRoleMapper authRoleMapper;


    @Override
    public BaseMapper getMapper() {
        return authRoleMapper;
    }
    public void processBeforeOperation(AuthRole entity, BaseOperationEnum operationEnum) throws CustomException {
    }

    public void processAfterOperation(AuthRole entity, BaseOperationEnum operationEnum) throws CustomException {
    }


    @Override
    public List<AuthRole> findRoleByUid(String uid) {
        return authRoleMapper.findRoleByUid(uid);
    }

    @Override
    public List<String> findRoleIdsByUid(String uid) {
        List<AuthRole> roles=authRoleMapper.findRoleByUid(uid);
        List<String> roleIds=new ArrayList<>();
        if(roles!=null && !roles.isEmpty()){
            for (AuthRole role : roles) {
                roleIds.add(role.getId());
            }
        }
        return roleIds;
    }

    @Override
    public List<AuthRoleDTO> findRoleByUsername(String username) {
        if(StrUtil.isNotEmpty(username)){
            return authRoleMapper.findRoleByUsername(username);
        }
        return new ArrayList<>();
    }
}
